<template>
  <div class="wrapper">
    <div class="item-boxes">
      <div v-for="(item, index) in dataArr" :key="index" class="item-box">
        <div class="name">{{ item[0].xm }}</div>
        <div class="value-wrapper">
          <span>{{ item[0].sz }}</span>
          <span>{{ item[0].dw }}</span>
        </div>
        <div class="rate">{{ item[1].sz + item[1].dw }}</div>
      </div>
    </div>
    <div class="bottom-row">
      <div class="name">{{ last[0].xm }}</div>
      <div class="value-wrapper">
        <span>{{ last[0].sz }}</span>
        <span>{{ last[0].dw }}</span>
      </div>
      <div class="rate rate--up">{{ last[1].sz + last[1].dw }}</div>
    </div>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'
import { chunk } from '@/utils/array'

export default {
  name: 'LocalTransportation',
  data() {
    return {
      dataArr: [],
      last: [[], []]
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    async loadData() {
      const res = await getAction(
        '/topic/data/listAllBySql/dy_ydd_jtys_dfjtys_gk',
        { lb: '地方交通运输' }
      )
      if (res.success) {
        const data = chunk(res.result, 2)
        this.last = data.pop() || []
        this.dataArr = data
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  .item-boxes {
    display: grid;
    grid-template-columns: repeat(3, 134px);
    grid-template-rows: repeat(2, 92px);
    gap: 5px 8px;

    .item-box {
      padding: 8px;
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 100%;
      height: 100%;
      background: url('../../images/left/l-t-bg.png') no-repeat,
        url('../../images/left/l-t-center.png') no-repeat center 53%;
    }
  }

  .name {
    font-family: MicrosoftYaHeiUI;
    font-size: 16px;
    color: #ffffff;
  }
  .value-wrapper {
    display: flex;
    align-items: center;

    span:first-child {
      margin-right: 4px;
      font-family: YouSheBiaoTiHei;
      font-size: 24px;
      color: #16fdf5;
      line-height: 1.5;
    }
    span:last-child {
      font-family: MicrosoftYaHeiUI;
      font-size: 14px;
      color: #ffffff;
      white-space: nowrap;
    }
  }
  .rate {
    display: flex;
    align-items: center;
    font-family: MicrosoftYaHeiUI, MicrosoftYaHeiUI;
    font-weight: bold;
    font-size: 16px;
    color: #ff3e3e;

    &::before {
      margin-right: 4px;
      display: block;
      width: 10px;
      height: 14px;
      background: url('../../images/left/up-arrow.png') no-repeat;
      background-size: 100% 100%;
      content: '';
    }
  }

  .bottom-row {
    margin-top: 6px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 49px;
    background: url('../../images/left/l-row-bg.png') no-repeat;
    background-size: 100% 100%;

    .value-wrapper {
      margin-top: 0;
      span:first-child {
        color: #ffde00;
      }
    }
  }
}
</style>
